package com.ruoyi.web.convert;

import com.ruoyi.basedata.domain.vo.TerminalsXbProtocol;
import com.ruoyi.datastatistics.domain.MeterHistoryData;
import com.ruoyi.datastatistics.domain.RealtimegatherdataXbForWW;

import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class ConvertForm {
   public static MeterHistoryData RealtimegatherdataXbFormWW(RealtimegatherdataXbForWW realtimegatherdataXbForWW, TerminalsXbProtocol terminalsDb) throws ParseException {
       if(realtimegatherdataXbForWW.getElecAddress().equals("")){
           return null;
       }
       SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
       Date readDate = sdf.parse(realtimegatherdataXbForWW.getReadingDT());
       sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
       MeterHistoryData meterHistoryData = new MeterHistoryData();
       meterHistoryData.setReadNumber( new BigDecimal(realtimegatherdataXbForWW.getTotalUp()));
       meterHistoryData.setReverseNumber(new BigDecimal(realtimegatherdataXbForWW.getTotalDown()));
       //realtimegatherdata.setInstantNumber(job.get("InstantNumber") != null? new BigDecimal(job.getString("InstantNumber")) : InstantNumber);
       meterHistoryData.setTotalFlow(new BigDecimal(realtimegatherdataXbForWW.getTotal()));
       meterHistoryData.setTerminalId(realtimegatherdataXbForWW.getElecAddress());
//       meterHistoryData.setRoomId(terminalsDb.getRoomId());
       meterHistoryData.setTenantId(terminalsDb.getTenantId());
       if(realtimegatherdataXbForWW.getBatteryVoltage() != null)
            meterHistoryData.setTerminalVol(new BigDecimal(realtimegatherdataXbForWW.getBatteryVoltage()));
       if(realtimegatherdataXbForWW.getRsrp() != null)
            meterHistoryData.setTerminalCsq(Integer.getInteger(realtimegatherdataXbForWW.getRsrp()));
       // realtimegatherdata.setTerminalCSQDescribe(signal);
       if(realtimegatherdataXbForWW.getValveStatus() != null)
            meterHistoryData.setValveState(realtimegatherdataXbForWW.getValveStatus().equals("00")? 1 : 2);
       meterHistoryData.setReadDate(sdf.format(readDate));
       meterHistoryData.setCreateDate(new Date());
       meterHistoryData.setSupplierId(terminalsDb.getSupplierId());
       return meterHistoryData;
   }
}
